package com.example.shushiyunsst

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import com.example.library_common.base.BaseActivityEx
import com.example.shushiyunsst.fragment.main.MainFragment
import com.example.shushiyunsst.fragment.sigin.SignPageFragment
import com.example.shushiyunsst.util.SoundUtils
import com.example.wallet.db.UserInfoManager
import com.umeng.message.IUmengCallback
import com.umeng.message.PushAgent
import me.yokeyword.fragmentation.anim.DefaultHorizontalAnimator
import me.yokeyword.fragmentation.anim.FragmentAnimator


class MainActivity : BaseActivityEx() {

    companion object {
        fun entry(context: Context) {
            val intent = Intent(context, MainActivity::class.java)
            intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
            context.startActivity(intent)
        }

        const val TAG="MainActivity22"

    }

    override fun onCreate(savedInstanceState: Bundle?) {

//        blackStatusBarText = false
        SoundUtils.getInstance().initPool(this)

        PushAgent.getInstance(this).onAppStart()

        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_main)

        if (savedInstanceState == null) {
            intiRootContentView()
        }


//        loadRootFragment(R.id.mContainer, MainFragment.newInstance())
    }

    private fun intiRootContentView() {
        if (UserInfoManager.userInfoManager.haveSignedIn()) {

            val mPushAgent = PushAgent.getInstance(this)

            mPushAgent.enable(object : IUmengCallback {
                override fun onSuccess() {
                    Log.d(TAG, "onSuccess:")
                }
                override fun onFailure(s: String, s1: String) {
                    Log.d(TAG, "onFailure: s= $s ,s1= $s1")
                }
            })

            loadRootFragment(R.id.mContainer, MainFragment.newInstance())
        } else {
            //            loadRootFragment(R.id.mContainer, SignInFragment.newInstance())

            val mPushAgent = PushAgent.getInstance(this)

            mPushAgent.disable(null)

            loadRootFragment(R.id.mContainer, SignPageFragment.newInstance())
        }
    }

    override fun onCreateFragmentAnimator(): FragmentAnimator {

        // 设置横向(和安卓4.x动画相同)
        return DefaultHorizontalAnimator()
    }

    override fun onDestroy() {
        super.onDestroy()

    }
}